/**
 *
 * @param lng: number | string | [lat==undefined and `lng` string format("%f,%f",lng,lat) @sample:"114.3,30.5"
 * @param lat: number | string
 * @usage:
 * lnglat(114.3,30.5)
 * lnglat("114.3,30.5")
 * lnglat("114.3","30.5")
 * @returns {ol.Coordinate}
 */
String.prototype.toProjectionLnglat = function () {
    return lnglat(String(this));
};

var lnglat = function (lng, lat) {
    var retLng, retLat;
    if (typeof(lng) == "number" && typeof(lat) == "number") {
        retLng = lng;
        retLat = lat;
    } else if ((typeof(lng) == "string" && typeof(lat) == "string")) {
        retLng = parseFloat(lng);
        retLat = parseFloat(lat);
    } else if (typeof(lng) == "string" && lat == undefined) {
        var splt = lng.split(',');
        retLng = parseFloat(splt[0]);
        retLat = parseFloat(splt[1])
    }
    return ol.proj.fromLonLat([retLng, retLat]);
};
/**
 * 跨域请求
 * @type {{getHtmlFromJSONP: req.getHtmlFromJSONP, getHtmlArrowCrossDomain: req.getHtmlArrowCrossDomain}}
 */
var req = {
    getHtmlFromJSONP: function (url, data, callbackName,callback, error) {
        if (data !== undefined || data !== null) data.output = "jsonp";
        $.ajax({
            type: "get",
            dataType: 'jsonp',
            data: data,
            jsonp: callbackName,
            url: url,
            success: callback,
            error: error
        });
    },
    getHtmlArrowCrossDomain: function (url, data, callback) {
        data.output = "jsonp";
        $.ajax({
            type: "get",
            data: data,
            url: url,
            success: callback
        });
    }
};

// var layersArray = map.getLayers().getArray();
// for (var i = 0; i < layersArray.length; i++) {
//     var option = document.createElement('option');
//     option.setAttribute("value", i);
//     option.innerText = layersArray[i].forName;
//     var select = document.getElementById('layers_select');
//     select.appendChild(option);
// }
var 汉阳月湖 = "114.24580073165887, 30.563638215148103".toProjectionLnglat();
var 沌口新区 = "114.19998315093831, 30.51016077989007".toProjectionLnglat();

var 汉口江滩 = "114.30383828399522, 30.59693519000659".toProjectionLnglat();
var 汉口花桥 = "114.26867461013775, 30.615838603719695".toProjectionLnglat();

var 武昌紫阳 = "114.30240607070907, 30.537298507814583".toProjectionLnglat();
var 青山钢花 = "114.38016867446878, 30.628480140181082".toProjectionLnglat();
var 东湖梨园 = "114.36671471405039, 30.571785986758954".toProjectionLnglat();
var 东湖高新 = "114.43150155178682, 30.50255394585423".toProjectionLnglat();

var wuhan = "114.241214, 30.572808".toProjectionLnglat();
var locations = [汉阳月湖, 沌口新区, 汉口江滩, 汉口花桥, 武昌紫阳, 东湖梨园, 青山钢花, 东湖高新];
var nameList="汉阳月湖, 沌口新区, 汉口江滩, 汉口花桥, 武昌紫阳, 东湖梨园, 青山钢花, 东湖高新";
nameList=nameList.split(", ");

function DataClass() {
    this.AQI=33;
    this.location="未知地址";
    this.time=new Date();
    this.setData=function (AQI,location,time){
        this.AQI=AQI;
        this.location=location;
        this.time=time;
    };
    // this.setData=function(){
    //     console.log(233)
    // };
    this.toString=function () {
        return "位 置 : " + this.location + "\n\n" +
            "AQI  :   " + this.AQI+"\n\n"+
            "时 间 : "+this.time;
    }
}

ol.Feature.prototype.dataEntity=new DataClass();

ol.Feature.prototype.instance = function () {
    return this.values_.features[0].dataEntity;
};

function getType(o) {
    return Object.prototype.toString.call(o).match(/^\[.* (.*)\]$/)[1].toLowerCase();
}

function arrayOfNulls(number) {
    var array=new Array(number);
    for(var i=0;i<array.length;i++){
        array[i]=null;
    }
    return array;
}
var Color={
    A:'#53e250',//绿
    B:'#a6f3ff',//浅蓝
    C:'#cec7c1',//灰色
    D:'#b765c0',//紫
    E:'#66337b',//暗紫
    F:'#42003f' //暗紫、黑
};
function chooseColorByAQI(AQI) {
    var color=Color.A;
    if(AQI<50){
        color=Color.A;
    }else if(AQI<100){
        color=Color.B;
    }else if(AQI<150){
        color=Color.C;
    }else if(AQI<250){
        color=Color.D;
    }else if(AQI<300){
        color=Color.E;
    }else{
        color=Color.F;
    }
    return color;
}
